package com.ruoyi.web.controller.wx_userAndShenhe;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.loginAndregist.domain.WxUser2;
import com.ruoyi.loginAndregist.service.IWxUserService2;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/*
*
* 后台管理接口
*
*
* 用户与审核管理
* */

@Controller
@RequestMapping("/wx_userAndShenhe/user")
public class UserAndSheheController extends BaseController {

    private String prefix = "wx_userAndShenhe/user";


    @Autowired
    private IWxUserService2 wxUserService;

    @RequiresPermissions("wx_userAndShenhe:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }






    /**
     * 查询wx用户列表
     */
    @RequiresPermissions("wx_userAndShenhe:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxUser2 wxUser)
    {
        startPage();
        List<WxUser2> list = wxUserService.selectWxUserList(wxUser);
        return getDataTable(list);
    }

    /**
     * 导出wx用户列表
     */
    @RequiresPermissions("wx_userAndShenhe:user:export")
    @Log(title = "wx用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxUser2 wxUser)
    {
        List<WxUser2> list = wxUserService.selectWxUserList(wxUser);
        ExcelUtil<WxUser2> util = new ExcelUtil<WxUser2>(WxUser2.class);
        return util.exportExcel(list, "user");
    }




    /**
     * 修改wx用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WxUser2 wxUser = wxUserService.selectWxUserById(id);
        mmap.put("wxUser", wxUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存wx用户
     */
    @RequiresPermissions("wx_userAndShenhe:user:edit")
    @Log(title = "wx用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxUser2 wxUser)
    {
        return toAjax(wxUserService.updateWxUser(wxUser));
    }



    /**
     * 删除wx用户
     */
    @RequiresPermissions("wx_userAndShenhe:user:remove")
    @Log(title = "wx用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxUserService.deleteWxUserByIds(ids));
    }


    //审核用户
    @GetMapping("/shenhe/{id}")
    public String shenhe(@PathVariable("id") Long id, ModelMap mmap)
    {
        WxUser2 wxUser = wxUserService.selectWxUserById(id);
        mmap.put("wxUser", wxUser);
        return prefix + "/edit";
    }

}
